package demo4.controller;

import demo4.mapper.iusermapper;
import demo4.pojo.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class usercontroller
{
    @Autowired
    private iusermapper mapper;
    public void start()
    {
        System.out.println("用户系统");
        Scanner sc=new Scanner(System.in);
        System.out.println("1.注册");
        System.out.println("2.登录");
        System.out.println("3.改密码");
        System.out.println("3.用户列表");
        int num=sc.nextInt();
        switch (num)
        {
            case 1:
                reg();
                break;
            case 2:
                login();
                break;
            case 3:
                System.out.println("改密码");
                break;
            case 4:
                System.out.println("用户列表");
                break;
            default:
                System.out.println("输入错误");
        }
    }
    private void reg()
    {
        System.out.println("开始注册");
        user user=new user();
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名");
        user.setUsername(sc.next());
        System.out.println("请输入密码");
        user.setPassword(sc.next());
        System.out.println("请输入昵称");
        user.setNickname(sc.next());
        System.out.println("请输入年龄");
        user.setAge(sc.nextInt());
        int num=mapper.insert(user);
        System.out.println(num>0?"成功":"失败");
        System.out.println("注册成功");
    }
    private void login()
    {
         Scanner ssc=new Scanner(System.in);
         System.out.println("请输入用户名");
         String name=ssc.next();
         System.out.println("请输入密码");
         String password=ssc.next();
         user user=mapper.select(name);
         if(user!=null)
         {
             if(user.getPassword().equals(password))
             {
                 System.out.println("登录成功");
             }
             else
             {
                 System.out.println("密码错误");
             }
         }else{
             System.out.println("用户不存在");
         }
    }
}
